class Solution {
public:
    vector<string> subdomainVisits(vector<string>& cpdomains) {
        vector<string>  ans;
/*["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]*/

        for (string& cpdomain : cpdomains) 
        {
 /*
"900 google.mail.com"
"50 yahoo.com"
"1 intel.mail.com"
"5 wiki.org"
*/           
            //string cpdomain;
            //"900 google.mail.com"
            //正则表达式分割? X too 复杂
            //
            int index_space = cpdomain.find(' ');
            int cpdomain_num = stoi(cpdomain.substr(0,index_space));
            string cpdomain_string = cpdomain.substr(index_space+1);

            while (index_space>0)
            {
                subcpdmains[cpdomain_string]+=cpdomain_num;
                index_space = cpdomain_string.find('.');
                cpdomain_string =  cpdomain_string.substr(index_space+1);
            }

        }
        
        for (auto subcpdmain_string : subcpdmains)
            {
                ans.push_back(to_string(subcpdmain_string.second)+" " +subcpdmain_string.first);
            }

        return ans;
    }
private:
    unordered_map<string,int> subcpdmains;
};